home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / amiga / sipp.lha / sipp / demo / strausstest.c < prev    next >
C/C++ Source or Header  |  1993-03-13  |  4KB  |  169 lines

  1. /*
  2.  * Demo of the strauss shader. Four spheres are rendered, 
  3.  * all with the same base color, but different smoothness
  4.  * and metalness.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <math.h>
  9.  
  10. #include <sipp.h>
  11. #include <shaders.h>
  12. #include <primitives.h>
  13.  
  14.  
  15. /*
  16.  * Surface description of the spheres.
  17.  */
  18. Strauss_desc non_metal_dull = {
  19.     0.4,                        /* Ambient */
  20.     0.2,                        /* Smoothness */
  21.     0.1,                        /* Metalness */
  22.     {0.6, 0.33, 0.27},          /* Color */
  23.     {1.0, 1.0, 1.0}             /* Opacity */
  24. };
  25.  
  26. Strauss_desc non_metal_shiny = {
  27.     0.4, 
  28.     0.7, 
  29.     0.1, 
  30.     {0.6, 0.33, 0.27}, 
  31.     {1.0, 1.0, 1.0}
  32. };
  33.  
  34. Strauss_desc metal_dull = {
  35.     0.4, 
  36.     0.2, 
  37.     0.9, 
  38.     {0.6, 0.33, 0.27}, 
  39.     {1.0, 1.0, 1.0}
  40. };
  41.  
  42. Strauss_desc metal_shiny = {
  43.     0.4, 
  44.     0.7, 
  45.     0.9, 
  46.     {0.6, 0.33, 0.27}, 
  47.     {1.0, 1.0, 1.0}
  48. };
  49.  
  50.  
  51. /*
  52.  * White surface as background.
  53.  */
  54. Surf_desc bg_surf = {
  55.     0.4,
  56.     0.0,
  57.     0.99,
  58.     {0.9804,  0.9216,  0.8431},  /* Antique white */
  59.     {1.0, 1.0, 1.0}
  60. };
  61.  
  62.  
  63.  
  64. #define RESOLUTION 30
  65.  
  66. extern char *optarg;
  67.  
  68. main(argc, argv)
  69.     int    argc;
  70.     char **argv;
  71. {
  72.     Object *nmd;     /* Non metallic, dull sphere */
  73.     Object *nms;     /* Non metallic, shiny sphere */
  74.     Object *md;      /* Metallic, dull sphere */
  75.     Object *ms;      /* Metallic, shiny sphere */
  76.     Object *bg;      /* Background */
  77.     FILE   *fp;
  78.  
  79.     char    *imfile_name;
  80.     int      mode;
  81.     int      c;
  82.     int      size;
  83.  
  84.     imfile_name = "strauss.ppm";
  85.     mode = PHONG;
  86.     size = 256;
  87.  
  88.     while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
  89.         switch (c) {
  90.           case 'p':
  91.             mode = PHONG;
  92.             imfile_name = "strauss.ppm";
  93.             break;
  94.  
  95.           case 'g':
  96.             mode = GOURAUD;
  97.             imfile_name = "strauss.ppm";
  98.             break;
  99.  
  100.           case 'f':
  101.             mode = FLAT;
  102.             imfile_name = "strauss.ppm";
  103.             break;
  104.  
  105.           case 'l':
  106.             mode = LINE;
  107.             imfile_name = "strauss.pbm";
  108.             break;
  109.  
  110.           case 's':
  111.             size = atoi(optarg);
  112.             break;
  113.         }
  114.     }
  115.  
  116.     sipp_init();
  117.  
  118.     lightsource_create(-1.0, -1.0, 1.0, 1.0, 1.0, 1.0, LIGHT_DIRECTION);
  119.     lightsource_create(0.0, -1.0, 2.0, 0.6, 0.6, 0.6, LIGHT_DIRECTION);
  120.  
  121.     /*
  122.      * Non metal, dull. Upper left.
  123.      */
  124.     nmd = sipp_sphere(1.0, RESOLUTION, &non_metal_dull, strauss_shader, WORLD);
  125.     object_move(nmd, -1.1, 0.0, 1.1);
  126.     object_add_subobj(sipp_world, nmd); 
  127.  
  128.     /*
  129.      * Non metal, shiny. Upper right.
  130.      */
  131.     nms = sipp_sphere(1.0, RESOLUTION, &non_metal_shiny, strauss_shader,
  132.                       WORLD); 
  133.     object_move(nms, 1.1, 0.0, 1.1);
  134.     object_add_subobj(sipp_world, nms); 
  135.  
  136.     /*
  137.      * Metal, dull. Lower left.
  138.      */
  139.     md = sipp_sphere(1.0, RESOLUTION, &metal_dull, strauss_shader, WORLD);
  140.     object_move(md, -1.1, 0.0, -1.1);
  141.     object_add_subobj(sipp_world, md); 
  142.  
  143.     /*
  144.      * Metal, shiny. Lower right.
  145.      */
  146.     ms = sipp_sphere(1.0, RESOLUTION, &metal_shiny, strauss_shader, WORLD);
  147.     object_move(ms, 1.1, 0.0, -1.1);
  148.     object_add_subobj(sipp_world, ms);
  149.  
  150.     /*
  151.      * Background.
  152.      */
  153.     bg = sipp_block(10.0, 0.5, 10.0, &bg_surf, basic_shader, WORLD);
  154.     object_move(bg, 0.0, 1.5, 0.0);
  155.     object_add_subobj(sipp_world, bg);
  156.  
  157.     camera_params(sipp_camera, 0.0, -10.0, 0.0,  0.0, 0.0, 0.0,  
  158.                   0.0, 0.0, 1.0,  0.25);
  159.  
  160.     printf("Rendering, wait...");
  161.     fflush(stdout);
  162.  
  163.     fp = fopen(imfile_name, "w");
  164.     render_image_file(size, size, fp, mode, 2);
  165.     printf("Done.\n");
  166.  
  167.     exit(0);
  168. }
  169.